//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    avatarUrl:"",
    nickName:"",
		city:'',
		gender:0,
		province:'',
    flag: 0,
    show:0,
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    
		shuxin: '职位属性',
    disabled:false,
    code: '',
    yzm: '获取验证码',
    paiming:0,
    list4:[],
    list1: [],
    list2: [],
		list3:[],
    iscode: null,
    dryingbtnid:1,
		inputValue1:'',
		inputValue2: '',
		inputValue3: '',
    _html:[],
    tel:"",
		user:{},
		hideFlag0:true,
		 
    select: false,
    select1: false,
    select2: false,
    select3: false,
		inputValue1_1: '',
		inputValue2_1: '',
    animationData: {},//
    value: '地区',
  },
  
  //取消
  mCancel: function () {
    var that = this;
    that.hideModal();
  },
  //取消
  mCancel0: function () {
    var that = this;
    that.hideModal0();
  },
  // 显示遮罩层
  showModal: function () {
    var that = this;
    that.setData({
      hideFlag: false
    })
    // 创建动画实例
    var animation = wx.createAnimation({
      duration: 400,//动画的持续时间
      timingFunction: 'ease',//动画的效果 默认值是linear->匀速，ease->动画以低速开始，然后加快，在结束前变慢
    })
    this.animation = animation; //将animation变量赋值给当前动画
    var time1 = setTimeout(function () {
      that.slideIn();//调用动画--滑入
      clearTimeout(time1);
      time1 = null;
    }, 100)
  },


// 时间隐藏遮罩层
  hideModal0: function () {
    var that = this;
    var animation = wx.createAnimation({
      duration: 400,//动画的持续时间 默认400ms
      timingFunction: 'ease',//动画的效果 默认值是linear
    })
    this.animation = animation
    that.slideDown();//调用动画--滑出
    var time1 = setTimeout(function () {
      that.setData({
        hideFlag0: true
      })
      clearTimeout(time1);
      time1 = null;
    }, 220)//先执行下滑动画，再隐藏模块

  },
  // 隐藏遮罩层
  hideModal1: function () {
    var that = this;
    var animation = wx.createAnimation({
      duration: 400,//动画的持续时间 默认400ms
      timingFunction: 'ease',//动画的效果 默认值是linear
    })
    this.animation = animation
    that.slideDown();//调用动画--滑出
    var time1 = setTimeout(function () {
      that.setData({
        hideFlag1: true
      })
      clearTimeout(time1);
      time1 = null;
    }, 220)//先执行下滑动画，再隐藏模块
  },

  mCancel2: function () {
    var that = this;
    that.hideModal2();
  },
  //动画 -- 滑入
  slideIn: function () {
    this.animation.translateY(0).step() // 在y轴偏移，然后用step()完成一个动画
    this.setData({
      //动画实例的export方法导出动画数据传递给组件的animation属性
      animationData: this.animation.export()
    })
  },
  //动画 -- 滑出
  slideDown: function () {
    this.animation.translateY(300).step()
    this.setData({
      animationData: this.animation.export(),
    })
  }, 
  onLoad: function (e) {
    let that = this;
    that.setData({
      role: app.globalData.role
    }) 
		console.log(app.globalData.userInfo)
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        avatarUrl: app.globalData.userInfo.avatarUrl,
        nickName: app.globalData.userInfo.nickName,
				city: app.globalData.userInfo.city,
				gender: app.globalData.userInfo.gender,
				province: app.globalData.userInfo.province,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          avatarUrl: app.globalData.userInfo.avatarUrl,
          nickName: app.globalData.userInfo.nickName,
					city: app.globalData.userInfo.city,
					gender: app.globalData.userInfo.gender,
					province: app.globalData.userInfo.province,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            avatarUrl: app.globalData.userInfo.avatarUrl,
            nickName: app.globalData.userInfo.nickName,
						city: app.globalData.userInfo.city,
						gender: app.globalData.userInfo.gender,
						province: app.globalData.userInfo.province,
            hasUserInfo: true
          })
        }
      })
    };
   
  },
  getUserInfo: function (e) {
    app.globalData.userInfo = e.detail.userInfo
    app.globalData.code = e.detail.code
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    });
  },
	 //查分数跳转
	lookfs: function (e) {
	  wx.redirectTo({
	    url: "../index/index"
	  })
	},
  //更多跳转
  more: function (e) {
    var _that = this;
    console.log(_that.data.userInfo)
    if (_that.data.userInfo == undefined) {
      var userInfo = ""
    } else {
      var userInfo = _that.data.userInfo;
    }
    var phone = _that.data.phone;
    wx.redirectTo({
      url: "../more/more?userInfo=" + JSON.stringify(userInfo) + "&phone=" + _that.data.tel
    })
  },
  //获取姓名value值
  bindKeyInput1: function (e) {
    this.setData({
      inputValue1: e.detail.value,
      inputValue1_1: 1
    })
  },
  inputBlur1: function (e) {
    this.setData({
      inputValue1_1: 0
    });
  },
  //获取手机号value值
  bindKeyInput2: function (e) {
    console.log(e)
    this.setData({
      inputValue2: e.detail.value,
      inputValue2_1: 1
    })
  },
  inputBlur2: function (e) {
    this.setData({
      inputValue2_1: 0
    });
  },
  //获取验证码value值
  bindKeyInput3: function (e) {
    this.setData({
      inputValue3: e.detail.value
    })
  },
  
  //事件处理函数
  bindViewTap: function() {
    wx.redirectTo({
      url: '../logs/logs'
    })
  },
  //信息查询切换
  switchNav: function (e) {
    console.log(e.currentTarget.id);    
    if (e.currentTarget.id==0){
      this.setData({
        dryingbtnid:1
      })
      console.log(this.data.dryingbtnid)
    }else{
      this.setData({
        dryingbtnid:2
      })
      console.log(this.data.dryingbtnid)
    }
    this.setData({
      flag: e.currentTarget.id,
      show: e.currentTarget.id
    })
  },
	 //职位属性下拉
	bindShowMsg0() {
	  var that = this;
	  that.setData({
	    hideFlag0: false,
	  })
	  // 创建动画实例
	  var animation = wx.createAnimation({
	    duration: 400,//动画的持续时间
	    timingFunction: 'ease',//动画的效果 默认值是linear->匀速，ease->动画以低速开始，然后加快，在结束前变慢
	  })
	  this.animation = animation; //将animation变量赋值给当前动画
	  var time1 = setTimeout(function () {
	    that.slideIn();//调用动画--滑入
	    clearTimeout(time1);
	    time1 = null;
	  }, 100)
	},
	mySelect0(e) {
	  var name = e.currentTarget.dataset.name
	  this.setData({
	    shuxin: name,
	    hideFlag0: true
	  })
	},
	
	//信息查询验证码获取
	getCode: function () {
	  var a = this.data.inputValue2;
	  var _this = this;
	  var myreg = /^1[3456789]\d{9}$/;
	  if (this.data.inputValue2 == "") {
	    wx.showToast({
	      title: '手机号不能为空',
	      icon: 'none',
	      duration: 1000
	    })
	    return false;
	  } else if (!myreg.test(this.data.inputValue2)) {
	    wx.showToast({
	      title: '请输入正确的手机号',
	      icon: 'none',
	      duration: 1000
	    });
	    return false;
	  } else {
	    wx.request({
	      url: "https://zg99.offcn.com/index/shaifen/sendmsg?actid=12241&callback=?",
	      data: {
	        phone: a,
	      },        
	      success(res) {
	        let bbb = res.data.replace(/(^\(*|\)*$)/g, "")
	        let obj = JSON.parse(bbb)
	        console.log(obj)
	        console.log(res.data.yh)
	        if (obj.status==1){
	            _this.setData({
	              iscode: res.data.yzm,
	              disabled:true
	            })
	            var num = 61;
	            var timer = setInterval(function () {
	              num--;
	              if (num <= 0) {
	                clearInterval(timer);
	                _this.setData({
	                  yzm: '重新发送',
	                  disabled: false
	                })
	              } else {
	                _this.setData({
	                  yzm: num + "s"
	                })
	              }
	            }, 1000)
	        } else if (obj.status == 2) {
	          wx.showToast({
	            title: obj.msg,
	            icon: 'none',
	            duration: 1000
	          })           
	        } else if (obj.status == 4) {
						app.globalData.login=1
	           wx.showToast({
	          	  title: "您已注册，可直接进行查询",
	          	  icon: 'none',
	          	  duration: 2000
	          	})
	          setTimeout(function(){
	           wx.redirectTo({
	            url: '../index/index?&phone=' + _this.data.inputValue2+ '&name=' + _this.data.inputValue1
	          })
	          },2000)
	        } else{ 
	          wx.showToast({
	            title: '验证码获取失败',
	            icon: 'none',
	            duration: 1000
	          })
	          clearInterval(timer);
	          _this.setData({
	            yzm: '重新发送',
	          })
	        }
	      }
	    })
	  }
	},
	//获取验证码
	getVerificationCode() {
	  this.getCode();
	  var _this = this  
	},
	
  //新用户查询
  getsearch:function(){
    var _that=this;
    var dryingbtnid = _that.data.dryingbtnid;  
    var typeid=_that.data.dryingbtnid;
    var myreg = /^1[3456789]\d{9}$/;
		var page=1
    if (_that.data.userInfo ==undefined){
      var nickname = "";
      var avatarurl = "";
      var userInfo=""
			var city = "";
			var gender = "";
			var province=""
    }else{
      var nickname = _that.data.userInfo.nickName;
      var avatarurl = _that.data.userInfo.avatarUrl;
      var userInfo = _that.data.userInfo;
			 var city = _that.data.userInfo.city;
			var gender = _that.data.userInfo.gender;
			var province = _that.data.userInfo.province;
    }
    
    console.log(JSON.stringify(userInfo))  
    // if (dryingbtnid==1){  
			console.log(this.data.list2)
			var shuxin = this.data.shuxin; 
      var name = this.data.inputValue1;
      var phone = this.data.inputValue2;
			var yzm = this.data.inputValue3;
				 console.log(2222)
      console.log(phone)
      console.log(avatarurl);
			 console.log(city);
			console.log(gender);
			console.log(province);
			if (shuxin=="职位属性"){
			  wx.showToast({
			    title: '职位属性不能为空',
			    icon: 'none',
			    duration: 1000
			  })
			  return false;
			}
      var reg2 = /^[\u4e00-\u9fa5]{2,10}$/;
      if (name == "") {
        wx.showToast({
          title: '姓名不能为空',
          icon: 'none',
          duration: 1000
        })
        return false;
      } else if (!reg2.test(name)) {
        wx.showToast({
          title: '姓名长度应在2-10之间，中文字符',
          icon: 'none',
          duration: 1000
        })
        return false;
      }
      if (phone == "") {
        wx.showToast({
          title: '手机号不能为空',
          icon: 'none',
          duration: 1000
        })
        return false;
      } else if (!myreg.test(phone)) {
        wx.showToast({
          title: '请输入正确的手机号',
          icon: 'none',
          duration: 1000
        });
        return false;
      }
				 wx.request({
				       url: 'https://zg99.offcn.com/index/shaifen/register?actid=12241&callback=?',
				                 data: {
				                   avatarurl: avatarurl,
				                   nickname: nickname,
				                   name: name,
				                   phone: phone,
				 									 gender:gender,
				                   yzm: yzm,
				 									 city:city,
				 									 province:province,
													 shuxin:shuxin
				                 },
				                 success: function (res) {
				 									 let bbb = res.data.replace(/(^\(*|\)*$)/g, "")
				 									let obj = JSON.parse(bbb)
				                   console.log(obj)
				                   if (obj.status == 1) {
														 wx.showToast({
														 	  title: obj.msg,
														 	  icon: 'none',
														 	  duration: 1000
														 	})
														 setTimeout(function(){
														  wx.redirectTo({
														   url: '../index/index?phone=' + _that.data.inputValue2+ '&name=' + _that.data.inputValue1
														 })
														 },1000)
				                   }else if(obj.msg=="验证码失效"){
				 											wx.showToast({
				 										  title: '验证码失效,请从新获取',
				 										  icon: 'none',
				 										  duration: 1500,
				 										})
				 									}else if(obj.msg=="验证码错误"){
				 											wx.showToast({
				 										  title: '验证码错误,请从新输入',
				 										  icon: 'none',
				 										  duration: 1500,
				 										})
				 									} 
				                 }
				               })
			},
			getsearch1() {
				this.getsearch();
			},
			onReady:function(){
				app.getuser();
			},
  onShareAppMessage:function(){
    var that = this;
    　　// 设置菜单中的转发按钮触发转发事件时的转发内容
    　　var shareObj = {
      　　　　title: "转发的标题",        // 默认是小程序的名称(可以写slogan等)
      　　　　path: '/pages/share/share',        // 默认是当前页面，必须是以‘/’开头的完整路径
      　　　　imageUrl: '',     //自定义图片路径，可以是本地文件路径、代码包文件路径或者网络图片路径，支持PNG及JPG，不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
      　　　　success: function (res) {
        　　　　　　// 转发成功之后的回调
        　　　　　　if (res.errMsg == 'shareAppMessage:ok') {
        　　　　　　}
      　　　　},
        fail: function () {
          　　　　　　// 转发失败之后的回调
          　　　　　　if (res.errMsg == 'shareAppMessage:fail cancel') {
            　　　　　　　　// 用户取消转发
          　　　　　　} else if (res.errMsg == 'shareAppMessage:fail') {
            　　　　　　　　// 转发失败，其中 detail message 为详细失败信息
          　　　　　　}
        　　　　},
        complete: function(){
          　　　　　　// 转发结束之后的回调（转发成不成功都会执行）
        　　　　}
    }
  } 
		})
  
	

